var res = {
   getUrlParams: function(purl,isNoToLower) {
       isNoToLower = isNoToLower || false;
          var url = purl || window.location.href;
          var paraObj = {};
          if(url.indexOf("?")<0){
           return paraObj;
          }
     url = url.replace('#','');
          var paraString = url.substring(url.indexOf("?")+1,url.length).split("&");
          if(!isNoToLower){
           for (var i=0; j=paraString[i]; i++){
                  paraObj[j.substring(0,j.indexOf("=")).toLowerCase()] = j.substring(j.indexOf("=")+1,j.length);
              }
          }else{
           for (var i=0; j=paraString[i]; i++){
             try{
               paraObj[j.substring(0,j.indexOf("="))] = decodeURIComponent(j.substring(j.indexOf("=")+1,j.length));
             }catch(ex){
               paraObj[j.substring(0,j.indexOf("="))] = unescape(j.substring(j.indexOf("=")+1,j.length));
             }
              }
          }
          return paraObj;
      }
};
var res = res.getUrlParams();
$(function(){ 
	vararray=res.res.split(",");
	var line = decodeURIComponent(res.from) + "->" + decodeURIComponent(res.to);
	var show_weight = decodeURIComponent(res.weight);
	var fuel_interval = vararray[0]+'~'+vararray[1];
	$("#line").html(line);
    $("#show_weight").html(show_weight);
    $("#fuel_interval").html(fuel_interval);
    $("#economic_driving").click(function(){
    	$.ajax({
            type:"post",
            url:"../php/economicTruck.php",
            data:{"from":decodeURIComponent(res.from), "to":decodeURIComponent(res.to), "weight":show_weight},
            success: function(data){
            	var carstyle;
            	var sup;
            	var inf;
            	var res = JSON.parse(data);
        		carstyle = res[0].carstyle;
             	sup = res[0].sup;
             	inf = res[0].inf;
                location.href = "economic_driving.html?fuel_interval="+fuel_interval+"&line="+line+"&carstyle="+carstyle+"&sup_inf="+inf+"~"+sup;
           }
        });
    });

    $("#fuel_efficient").click(function(){
        location.href = "fuel_efficient.html";
    });
});
